package com.greate.community.controller;

import com.alibaba.fastjson.JSONArray;
import com.greate.community.entity.Exp;
import com.greate.community.entity.Page;
import com.greate.community.entity.Result;
import com.greate.community.service.ExpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 类名称：ExpController
 * 类描述：经验控制器
 * 创建人：CSUpipixia
 * 创建时间：2022/2/10 13:31
 *
 * @version v1.0
 */
@RestController
public class ExpController extends BaseController {

    @Autowired
    private ExpService expService;

    @PostMapping("/exp/page")
    public Result getPageOfExpLog(@RequestBody Page page) {
//        return new Result("success", Result.SUCCESS, expService.getExpPageByUserId(getUser().getId(), page.getOffset(), page.getLimit()));

        List<Exp> expList = expService.getExpPageByUserId(getUser().getId(), page.getOffset(), page.getLimit());
        JSONArray result = (JSONArray) JSONArray.toJSON(expList);
        page.setResult(result);
        return new Result("success", Result.SUCCESS, page);
    }
}
